import http from "assets/api/http";

const baseUrl = "http://localhost:8080";

// 获取一张二维码图片的地址 及其对应的 唯一的id
export const getLoginQrImagePath = () => {
    return http.requestGet("/user/pc-login-qr-code");
}

// 解析token 获取自己的信息
export const checkToken = () => {
    return http.requestGet("/user/get-own-info");
};

// 登录
export const doLogin = (captchaCode, LRUser) => {
    return http.requestPost("/user/login/" + captchaCode + "?from=pc_", LRUser);
};

// 获取用户列表
export const listUsers = (_page, _size) => {
    return http.requestGet("/user/list?page=" + _page + "&size=" + _size);
}

// 更新用户信息
export const putUser = (_user) => {
    return http.requestPut("/user/" + _user.id, _user);
}

// 删除用户
export const deleteUser = (_id) => {
    return http.requestDelete("/user/" + _id);
}


// 获取用户列表
export const searchUsers = (_page, _size, _userName, _email) => {
    return http.requestGet("/user/list?page=" + _page + "&size=" + _size + "&userName=" + _userName + "&email=" + _email);
}

// 获取邮箱验证码的接口
export const getVerifyCode = (_email) => {
    return http.requestGet("/user/verity_code/" + _email);
}

// 更新邮箱的接口
export const updateEmail = (_email, _verifyCode) => {
    return http.requestPut("/user/email/?email=" + _email + "&verify_code=" + _verifyCode);
}

// 获取自己的信息
export const getOwnInfo = () => {
    return http.requestGet("/user/get-own-info");
}

// 获取用户数量
export const getUserCount = () => {
    return http.requestGet("/user/register_count");
}

export const doLogout = () => {
    return http.requestGet("/user/logout")
};

export const doRegister = (_captcha, _verifyCode, _user) => {
    return http.requestPost("/user/join_in?captcha_code=" + _captcha + "&verify_code=" + _verifyCode, _user);
}

export const sendEmailVerifyCode = (_email) => {
    return http.requestGet("/user/verity_code/" + _email);
}

export const checkUserNameUnique = (_userName, _id) => {
    return http.requestGet("/user/username?username=" + _userName + "&id=" + _id)
}

export const checkEmailUnique = (_email, _id) => {
    return http.requestGet("/user/email?email=" + _email + "&id=" + _id)
}

export const checkEmailVerifyCode = (_email, _verifyCode) => {
    return http.requestGet("/user/check_email_code/" + _email + '/' + _verifyCode)
}

export const checkCaptchaCode = (_captchaCode) => {
    return http.requestGet("/user/check_captcha_code/" + _captchaCode);
}

//更新密码使用邮箱
export const updatePasswordByEmail = (_verifyCode, _user) => {
    return http.requestPut("/user/password/" + _verifyCode, _user);
}


export const getUserInfo = (_userId) => {
    if (process.client) {
        return http.requestGet("/user/user_info/" + _userId);
    } else {
        return http.requestGet(baseUrl + "/user/user_info/" + _userId);
    }
}